/**
  ******************************************************************************
  * @file    systick.c
  * @author  MCU SD
  * @version V1.0
  * @date    16-Nov-2015
  * @brief   SysTick functions.
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "soft_config.h"
#include "pin_config.h"
#include "systick.h"

static volatile uint32_t TimingDelay;
static __IO uint32_t runtimeCnt;

extern void in_systick_int(void);

/**
  * @brief  Inserts a delay time.
  * @param  nTime: specifies the delay time length, in milliseconds.
  * @retval None
  */
void Delay_ms(uint32_t nTime)
{
    TimingDelay = nTime;
    while(TimingDelay != 0);
}

uint32_t app_get_runtimeCnt(void)
{
	return runtimeCnt;
}

/**
  * @brief  Decrements the TimingDelay variable.
  * @param  None
  * @retval None
  */
void SysTick_Handler(void)
{
    if (TimingDelay != 0x00)
    {
        TimingDelay--;
    }

	runtimeCnt++;

	in_systick_int();
}

/* Private functions ---------------------------------------------------------*/
/**
  * @brief  Configure a SysTick Base time to 100us.
  * @param  None
  * @retval None
  */
void SysTick_Configuration(void)
{
    /* Setup SysTick Timer for 1ms interrupts  */
    if(SysTick_Config(FCLK / 1000))
    { 
        /* Capture error */ 
        while (1);
    }
    /* Configure the SysTick handler priority */
    NVIC_SetPriority(SysTick_IRQn, 0x00);
}
/******************* (C) COPYRIGHT 2015 GIGADEVICE *****END OF FILE****/
